﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using THO7AlgorithmBase;

namespace OCR_LEARN
{
    public partial class MainForm : Form
    {
        String folderPath;
        public MainForm()
        {
            InitializeComponent();
        }

        private void loadButton_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog FBD = new FolderBrowserDialog();
            if (FBD.ShowDialog() == DialogResult.OK)
            {
                folderPath = FBD.SelectedPath;
                InfoLabel.Text = folderPath + "\n";
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }


        private void OCRstart(object sender, EventArgs e) {
            OCR ocr = new OCR("OCR");
            GuidoOCR guidoOCR = new GuidoOCR();
            KuijlOCR Kk = new KuijlOCR();
            TjerkOCR to = new TjerkOCR();
            
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo(folderPath);
            try {
                files = Dir.GetFiles("*.*");
            } catch (UnauthorizedAccessException ex) { String error = ex + "\n"; }
            if (files != null){
                File.Delete(@"tjerkocr.txt");
                File.Delete(@"Data.txt");
                foreach (System.IO.FileInfo fi in files){
                    if (fi.Extension == ".BMP" || fi.Extension == ".PNG" || fi.Extension == ".bmp" || fi.Extension == ".jpg") {
                        //ocr.OCR_learn(new Bitmap(fi.FullName), fi.Name.Substring(0, fi.Name.IndexOf('.')));
                        //guidoOCR.learn(new Bitmap(fi.FullName), fi.Name.Substring(0, fi.Name.IndexOf('.')));
                        to.learn(new Bitmap(fi.FullName), fi.Name.Substring(0, fi.Name.IndexOf('.')));
                        //Kk.DoIt(new Bitmap(fi.FullName), fi.Name.Substring(0, fi.Name.IndexOf('.')));
                    }
                }
                InfoLabel.Text += "klaar\n";
            }
        }
    }
}
